from django.shortcuts import render_to_response
#from django.template.loader import get_template
from django.http import HttpResponse
#from django.template import Template, Context
import datetime

def hello(request):
    return HttpResponse("<h1>Hello World</h1>")

def current_datetime(request):
    now = datetime.datetime.now()
    #t = get_template('current_datetime.html')
    #html = t.render(Context({'current_date':now}))
    return render_to_response('current_datetime.html', {'current_date':now})

def hours_ahead(request, offset):
    try:
        offset = int(offset)
    except ValueError:
        raise Http404()

    dt = datetime.datetime.now()+datetime.timedelta(hours=offset)
    #html = "<html><body>In %s hour(s), it will be %s"%(offset,dt)
    #return HttpResponse(html)
    return render_to_response('hours_ahead.html',{'hour_offset':offset,
                                                  'next_time':dt})
def good(request):
    ua = request.META.get('HTTP_USER_AGENT', 'unknown')
    return HttpResponse("you brower is %s" % ua)

def display_meta(request):
    values = request.META.items()
    values.sort()
    return render_to_response('display_meta.html',{'values':values})

def show_color(request):
    #request.session['favorite_color'] = 'blue'
    if 'favorite_color' in request.GET:
        response = HttpResponse('Your favorite color is %s' % request.GET['favorite_color'])
        response.set_cookie("favorite_color", request.GET['favorite_color'])
        return response
    else:
        return HttpResponse("You don't have a favorite color!") 
